import {listName, listNone, postTree} from "@/api/projectManage/project";
import {list} from "@/api/projectManage/workItem";
import {DynamicNum} from "@/api/projectManage/demand";
import Logo from "@/layout/components/Sidebar/Logo";
import {postList} from "@/api/projectManage/membership";
// 公共方法
export const mixin = {
  data () {
    return {
      flawSevOption: [
        {
          label: '致命',
          value: 1,
        },
        {
          label: '严重',
          value: 2,
        },
        {
          label: '一般',
          value: 3,
        },
        {
          label: '轻微',
          value: 4,
        }
      ],
      flawPorOption: [
        {
          label: '大概率',
          value: 1,
        },
        {
          label: '小概率',
          value: 2,
        },
      ],
      cProHeadOption: [],
      allPersonnel: [],
      cDemPriOption: [
        {
          label: '最高',
          value: 1
        },
        {
          label: '较高',
          value: 2
        },
        {
          label: '普通',
          value: 3
        },
        {
          label: '较低',
          value: 4
        }
      ],
      ascriptionOption: [],
      demandOption: [
        {
          label: '产品研发',
          value: 1
        }
      ],
      startTime: '',
      endTime: '',
      selectTable: [],
      roleList: [],
      cProStateOption: [
        {
          label: '未开始',
          value: '1',
        },
        {
          label: '进行中',
          value: '2',
        },
        {
          label: '开发完成',
          value: '3',
        },
        {
          label: '测试完成',
          value: '4',
        },
        {
          label: '已上线',
          value: '5',
        }
      ],
      memberList: []
    }
  },
  computed: {
    projectInfo() {
      return JSON.parse(sessionStorage.getItem('projectInfo'))
    },
  },
  methods: {
    getPostList() {
      postList().then(res => {
        this.memberList = res.rows
      })
    },
    // 获取人员树
    getTree() {
      this.participantList = []
        postTree().then(res => {
        this.allPersonnel = res
        if (this.ruleForm.cTxt) {
          this.participantList = JSON.parse(this.ruleForm.cTxt)
        }
      })
    },
    // 获取所有成员
    getMember() {
      this.cProHeadOption = []
      listNone().then(res => {
        if (res.length) {
          res.forEach(i => {
            this.cProHeadOption.push({
              label: i.nickName,
              value: i.userId
            })
          })
        }
      })
    },
    // 处理工作项类型
    handelCPmType(type) {
      if (type == 10) return '项目'
      if (type == 11) return '需求'
      if (type == 12) return '缺陷'
      if (type == 13) return '任务'
    },
    // 获取项目归属
    getListName() {
      this.ascriptionOption = []
      listName('').then(res => {
        for (const k in res.data) {
          this.ascriptionOption.push({
            label: res.data[k],
            value: k
          })
        }
      })
    },
    // 处理时间格式
    handelTime() {
      if (this.startTime) this.ruleForm.tStaTm = new Date(this.startTime).getTime()
      if (this.endTime) this.ruleForm.tEndTm = new Date(this.endTime).getTime()
      console.log()
      console.log(new Date(this.startTime).getTime())
      console.log(this.ruleForm)
    },
    //偶数加背景色
    tableClass({ row, rowIndex }) {
      if (rowIndex % 2 == 1) {
        //奇数行，序号不能被2整除
        return "even-row";
      } else {
        return "";
      }
    },
    // 处理页面组件切换
    handleLink(link) {
      this.tabLink = link
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.selectTable = selection
    },
    // 等级动态类名
    handleIcon(value) {
      let color = 'gray'
      if (value == 1) color = 'red2'
      if (value == 2) color = 'orange'
      if (value == 3) color = 'blue'
      return `icon ${color}`
    },
    // 查询工作项
    getWorkItem(no) {
      this.configList = []
      list({
        cPmNo: no
      }).then(res => {
        this.configList = res.rows
      })
    },
    // 查询动态数量
    DynamicNum(no) {
      DynamicNum(no).then(res => {
        this.tablist[0].num = res.data.cProNum
        this.tablist[1].num = res.data.cProNum1
        this.tablist[2].num = res.data.cProNum2
        this.tablist[3].num = res.data.cProNum3
      })
    }
  }
}
